app.controller("cleanCtrl", ['$scope', '$window', '$stateParams', '$timeout', '$http', '$state', '$cookieStore', 'Md5', function ($scope, $window, $stateParams, $timeout, $http, $state, $cookieStore, Md5) {
    //    设置页面title
    $window.document.title = $stateParams.title;
    console.log($stateParams)
    // 保洁登录
    if ($cookieStore.get('cleanId')) {
        $http({
            method: 'post',
            url: $scope.httptit + '/index/clean/lst.html',
            data: {
                // id:$cookieStore.get("cleanId")
                id: $cookieStore.get("cleanId")
                // openID:'ksksk123456',
                // lng:data.position.getLng(),
                // lat:data.position.getLat()

            },
            dataType: 'json',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            transformRequest: $scope.changeData
        }).then(function successCallback(response) {
            $scope.forClean = response.data.data
            console.log($scope.forClean)
        }, function errorCallback(response) {
            console.log(response)
            // 请求失败执行代码
        });
        $state.go('forClean');
    } else {
        $state.go('loginClean');
    }

    $scope.openClean = function () {
        if ((/^1(3|4|5|7|8)\d{9}$/.test($scope.cleanAccount))) {
            $http({
                method: 'post',
                url: $scope.httptit + '/index/clean/login.html',
                data: {
                    phone: $scope.cleanAccount,
                    password: $scope.cleanPassWord
                },
                dataType: 'json',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                transformRequest: $scope.changeData
            }).then(function successCallback(response) {
                console.log(response.data)
                if (response.data.status == 101) {
                    $cookieStore.put('cleanId', response.data.data)//加密
                    console.log(response.data)
                    // 登录成功请求加载数据
                    $http({
                        method: 'post',
                        url: $scope.httptit + '/index/clean/lst.html',
                        data: {
                            id: response.data.data
                        },
                        dataType: 'json',
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                        transformRequest: $scope.changeData
                    }).then(function successCallback(response) {
                        $scope.forClean = response.data.data
                        console.log($scope.forClean[0])
                    }, function errorCallback(response) {
                        console.log(response)
                        // 请求失败执行代码
                    });
                    $state.go('forClean');
                }else if (response.data.status == 102) {
                    $scope.cleanAccount = ''
                    $scope.cleanPassWord = ''
                    $.alert({
                        title: '登录',
                        text: '账号或密码错误，请重新登录',

                    });
                }
            }, function errorCallback(response) {
                console.log(response)
                $.alert({
                        title: '登录',
                        text: response,

                    });
                                // 请求失败执行代码
            });
        } else {
            $scope.cleanAccount = ''
            $scope.cleanPassWord = ''
            $.alert({
                title: '登录',
                text: '手机号输入错误，请重新输入',
  
            });
        }

    }
    //点击完成打扫，删除完成打扫的数据
    $scope.outcleanList = function (index, v, c) {
        $.confirm({
            title: '房间打扫',
            text: '确认完成打扫',
            onOK: function () {
                $http({
                    method: 'post',
                    url: $scope.httptit + '/index/clean/out.html',
                    data: {
                        house_id: v,
                        cleaner_id: c
                    },
                    dataType: 'json',
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                    transformRequest: $scope.changeData
                }).then(function successCallback(response) {
                    // $scope.forClean=response.data.data

                    console.log(response.data)

                }, function errorCallback(response) {
                    console.log(response)
                    // 请求失败执行代码
                });
                //点击确认
                $timeout(function () {
                    $scope.forClean.splice(index, 1);
                }, 10)
            },
            onCancel: function () {
            }
        });


    }





}]);
